import type { Ihandler, ExtendedDocument } from '@/types/utils/dom'
export class WindowResizeChange {
  private _resizeThrottled: boolean = false
  private delay: number
  constructor(handler: Ihandler, delay = 250) {
    this.delay = delay
    const { handleResize } = this
    const func = handleResize.bind(this, handler)
    func()
  }
  checkIsMobile() {
    const clientWidth = window.innerWidth
    return clientWidth <= 750
  }
  resizeListener(handler: Ihandler) {
    let { delay, checkIsMobile } = this;
    if (!this._resizeThrottled) {
      this._resizeThrottled = true
      const timer = setTimeout(() => {
        handler(checkIsMobile())
        this._resizeThrottled = false
        clearTimeout(timer)
      }, delay)
    }
  }
  handleResize(handler: Ihandler) {
    const { resizeListener } = this;
    window.onresize = resizeListener.bind(this, handler)
  }
}

export const checkFull = () => {
  const htmlDocument: ExtendedDocument = document;
  const isFull = htmlDocument.mozFullScreen || htmlDocument.fullScreen || htmlDocument.webkitIsFullScreen || htmlDocument.webkitRequestFullScreen || htmlDocument.mozRequestFullScreen || htmlDocument.msFullscreenEnabled
  return !!isFull
}